//
//  MyCenterViewController.m
//  PatientApp
//
//  Created by chirui on 17/5/2.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "MyCenterViewController.h"
#import "ChangeMessageVC.h"
#import "MyCenterCViewCell.h"
#import "MyCenterCollectionReusableView.h"
#import "SettingViewController.h"
#import "MyPointViewController.h" // 我的积分

#import "MyOrderViewController.h" // 我的订单
#import "CartViewController.h" // 购物车
#import "AddressListViewController.h" // 地址
#import "ScoreFGoodsDetailsViewController.h" //积分商城详情
#import "SeeServiceViewController.h" //售后
#import "SeeRefundingViewController.h" // 退换货


@interface MyCenterViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UINavigationControllerDelegate>
{
    
    UICollectionView * _collectionView;
    NSDictionary * userDic;
    
    
    NSMutableArray * _dataArray;
    int _page;
    int _totailPage;

}

@end

@implementation MyCenterViewController




//- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
//    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
//        return (UIImageView *)view;
//    }
//    for (UIView *subview in view.subviews) {
//        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
//        if (imageView) {
//            return imageView;
//        }
//    }
//    return nil;
//}


-(void)viewWillDisappear:(BOOL)animated {
    
//    self.tabBarController.tabBar.hidden=NO;
    self.navigationController.navigationBarHidden =NO;
    
}

-(void)viewWillAppear:(BOOL)animated {
    
//    self.tabBarController.tabBar.hidden=YES;
    self.navigationController.navigationBarHidden = YES; //隐藏
    
    if (verifTokenAndEnter) {
        
        [self getUserMessageRequest];
        
        
    }else {
        userDic = nil;
        
         [_collectionView reloadData];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _page = 1;
    _dataArray= @[].mutableCopy;
    TitleView(@"我的")
    
    self.navigationController.navigationBarHidden = YES;
    
    [self creatCollectionView];
    
    if (verifTokenAndEnter) {
        
      [self getScoreGoodsListData];
    }else {
        
         [_collectionView reloadData];
    }
}

-(void)settingClick:(UIButton *)btn {
    
    if (verifTokenAndEnter) {
        SettingViewController * set = [[SettingViewController alloc]init];
        set.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:set animated:YES];
    }else {
        LogingViewController * login =[[LogingViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }
}

#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}


#pragma creatCollectionView

-(void)creatCollectionView {
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, -20, WIDTH, HEIGHT-28) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:_collectionView];
    _collectionView.showsVerticalScrollIndicator = NO;
    
    MJRefreshNormalHeader * header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
     
        _page = 1;
        
        if (verifTokenAndEnter) {
            
            [self getScoreGoodsListData];
        }else {
           
            [_collectionView.mj_header endRefreshing];
            
            [_collectionView reloadData];
        }
       
        
    }];
    _collectionView.mj_header = header;
    
    MJRefreshAutoNormalFooter *  footer =[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        _page++;
        
        if (verifTokenAndEnter) {
            
            [self getScoreGoodsListData];
        }else {
            
            [_collectionView.mj_footer endRefreshing];

        }
       
    }];
    
    footer.automaticallyRefresh = YES;
    _collectionView.mj_footer =footer;
    
    if (_dataArray.count>10) {
         _collectionView.mj_footer.hidden = NO;
    }else {
    
         _collectionView.mj_footer.hidden = YES;
    }
   
    
    //注册cell类
    [_collectionView registerNib:[UINib nibWithNibName:@"MyCenterCViewCell" bundle:nil] forCellWithReuseIdentifier:@"MyCenterCViewCell"];
    
    //    注册header类
    [_collectionView registerClass:[MyCenterCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyCenterCollectionReusableView"];
    
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return _dataArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary * dic = _dataArray[indexPath.row];
    MyCenterCViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCenterCViewCell" forIndexPath:indexPath];
    cell.clipsToBounds = NO;
    
    [cell.goodsImage sd_setImageWithURL:ImageUrl(dic[@"img_src"]) placeholderImage:ImageName(@"img_new_default")];
    
     cell.gooseName.frame = CGRectMake(6, CGRectGetMaxY(cell.goodsImage.frame)+5, (WIDTH-10)/2-12, 20);
    cell.gooseName.text = dic[@"goods_name"];
   
    cell.gooseName.numberOfLines = 2;
    [cell.gooseName sizeToFit];
    
    cell.scoreLabel.text = [NSString stringWithFormat:@"%@积分",dic[@"level_score"]];
        return cell;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    NSDictionary * dataDic = _dataArray[indexPath.row];

    if (verifTokenAndEnter) {
        ScoreFGoodsDetailsViewController * goods =[[ScoreFGoodsDetailsViewController alloc]init];
        goods.urlStr = dataDic[@"url"];
        goods.hidesBottomBarWhenPushed = YES;
        goods.goods_id = dataDic[@"goods_id"];
        [self.navigationController pushViewController:goods animated:YES];
    }else {
    
        LogingViewController * login =[[LogingViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    //    第一个参数是宽，第二个参数是高 5s  1.8   6 1.6   6p
    float height;
    if (ISP5||ISP4) {
        height = 1.5;
    }else if (ISP6){
        height = 1.3;
        
    }else if (ISP6P){
        height = 1.4;
    }
    
    CGSize size=CGSizeMake((WIDTH-10)/2, (WIDTH-10)/2*height);
    
    return size;
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //上 左 下 右
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

//设置水平间隙   默认10
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

////设置垂直间隙  默认10
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    return CGSizeMake(0,694+80);
}
//设置footer的宽度
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    //第一个参数：水平滑动时footer的宽度
    //第二个参数：垂直滑动时footer的高度
    return CGSizeMake(0, 0);
}

//kind:第二个参数:区分组头,组尾
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        
        
        
        MyCenterCollectionReusableView * collectView = [_collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"MyCenterCollectionReusableView" forIndexPath:indexPath];
        for (UIView * view in collectView.subviews) {
            
            [view removeFromSuperview];
        }
        
        collectView.backgroundColor =[UIColor groupTableViewBackgroundColor];
        UIView * heardView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 694+80)];
        heardView.backgroundColor =[UIColor whiteColor];
        
        [collectView addSubview:heardView];
        UIImageView * bgImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 120+64)];
        bgImage.userInteractionEnabled = YES;
        bgImage.image = ImageName(@"img_home_nav_bg");
        [heardView addSubview:bgImage];
        
        
        UILabel * titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(100, 30, WIDTH -200, 20)];
        titleLabel.font =[UIFont systemFontOfSize:17];
        titleLabel.textColor =[UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.text = @"我的";
        [bgImage addSubview:titleLabel];
        
        
        
        UIButton * setBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        setBtn.frame = CGRectMake(WIDTH - 50, 24, 30, 30);
//        setBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
        [setBtn setBackgroundImage:ImageName(@"icon_user_install") forState:UIControlStateNormal];
        [setBtn addTarget:self action:@selector(settingClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgImage addSubview:setBtn];
        
        
        UIImageView * rollImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 60+64, WIDTH, 60)];
        rollImage.userInteractionEnabled = YES;
        rollImage.image = ImageName(@"img_user_bg");
        [bgImage addSubview:rollImage];
        
        
        UIButton * iconBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.frame = CGRectMake(WIDTH/2-30, 94, 60, 60);
        iconBtn.layer.cornerRadius = 30.f;
        iconBtn.layer.masksToBounds = YES;
        [iconBtn setBackgroundImage:ImageName(@"img_user_default") forState:UIControlStateNormal];
        [iconBtn addTarget:self action:@selector(iconBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [bgImage addSubview:iconBtn];
        
        UILabel * nameLabel =[[UILabel alloc]initWithFrame:CGRectMake(30, 160, WIDTH/2 -20, 20)];
        nameLabel.font =[UIFont systemFontOfSize:15];
        nameLabel.textColor =[UIColor blackColor];
        nameLabel.textAlignment = NSTextAlignmentRight;
        nameLabel.text = @"红福人家";
        [bgImage addSubview:nameLabel];
        
        UIImageView * starImage =[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/2+15, 162.5, 15, 15)];
        starImage.image = ImageName(@"icon_user_score");
        [bgImage addSubview:starImage];
        
        NSArray * pointArray=@[@"0",@"0",@"0",@"0"];
        
        if (userDic) {
            
            
            NSString * nameStr = userDic[@"user_name"];
            [iconBtn sd_setBackgroundImageWithURL:userDic[@"avatar"] forState:UIControlStateNormal placeholderImage:ImageName(@"img_user_default")];
            nameLabel.text = userDic[@"user_name"];
            
            if (verifTokenAndEnter) {
                 pointArray=@[userDic[@"goal_score"],userDic[@"history_score"],userDic[@"current_score"],userDic[@"available_score"]];
            }
            
            if (nameStr.length<=0) {
                nameLabel.text = @"未设置";
            }
        }else {
        
            pointArray =@[@"0",@"0",@"0",@"0"];
        }
        
        
         UIView * goldBtnView = [self creatTitleViewFrame:CGRectMake(0, 184, WIDTH, 50) andBageColor:[UIColor whiteColor] ImageName:@"icon_user_gold" andTitle:@"我的金币" andSel:@selector(goldViewBtn:) andMoreImageHidden:NO onView:heardView];
        
        UILabel * goldLabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 15, WIDTH - 180, 20)];
        goldLabel.textAlignment = NSTextAlignmentRight;
        goldLabel.text = @"29287398298";
        goldLabel.font = [UIFont systemFontOfSize:14];
        goldLabel.textColor = [UIColor orangeColor];
        [goldBtnView addSubview:goldLabel];
        

        UIView * pointBtnView = [self creatTitleViewFrame:CGRectMake(0, 234, WIDTH, 50) andBageColor:[UIColor whiteColor] ImageName:@"icon_user_integral" andTitle:@"我的积分" andSel:@selector(pointViewBtn:) andMoreImageHidden:NO onView:heardView];
        
        NSArray * title_array = @[@"本年度目标",@"历史预留",@"当前积分",@"可用积分"];

        for (int i = 0; i<2; i++) {
            UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0+WIDTH/2*i, CGRectGetMaxY(pointBtnView.frame)+10 , WIDTH/2, 60)];
            
            UILabel * numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, WIDTH/2, 20)];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.textColor = [UIColor redColor];
            numberLabel.font =[UIFont systemFontOfSize:14];
            numberLabel.text = pointArray[i];
            [view addSubview:numberLabel];
            UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, WIDTH/2, 20)];
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.textColor = [UIColor blackColor];
            titleLabel.font =[UIFont systemFontOfSize:14];
            titleLabel.text = title_array[i];
            [view addSubview:titleLabel];
            
            view.backgroundColor =[UIColor whiteColor];
            [heardView addSubview:view];
            if (i<1) {
                
                UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH/2-0.5, 25, 0.5, 30)];
                lineView.backgroundColor =RGB(0xe5e5e5);
                [view addSubview:lineView];
            }
            
        }
        
        for (int j=0; j<2; j++) {
            
            UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0+WIDTH/2*j, CGRectGetMaxY(pointBtnView.frame)+70 , WIDTH/2, 60)];
            
            UILabel * numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, WIDTH/2, 20)];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.textColor = [UIColor redColor];
            numberLabel.font =[UIFont systemFontOfSize:14];
            numberLabel.text = pointArray[j+2];
            [view addSubview:numberLabel];
            
            UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, WIDTH/2, 20)];
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.textColor = [UIColor blackColor];
            titleLabel.font =[UIFont systemFontOfSize:14];
            titleLabel.text = title_array[j+2];
            [view addSubview:titleLabel];
            
            view.backgroundColor =[UIColor whiteColor];
            [heardView addSubview:view];
            if (j<1) {
                
                UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH/2-0.5, 25, 0.5, 30)];
                lineView.backgroundColor = RGB(0xe5e5e5);
                [view addSubview:lineView];
            }
            
        }
        
        UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(pointBtnView.frame)+140, WIDTH, 10)];
        lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [heardView addSubview:lineView];
        
        
        UIView * orderView = [self creatTitleViewFrame:CGRectMake(0, CGRectGetMaxY(pointBtnView.frame)+150, WIDTH, 50) andBageColor:[UIColor whiteColor] ImageName:@"icon_user_order" andTitle:@"我的订单" andSel:@selector(orderBtn:) andMoreImageHidden:NO onView:heardView];
        
        float width  = WIDTH/3;
        NSArray * twoArray = @[@"icon_user_gr",@"icon_user_rg",@"icon_user_cs"];
        NSArray * twoTitleArray = @[@"待收货",@"退换货",@"售后"];
        
        UIView *  twoView;
        for (int j = 0; j<3; j++) {
            
            twoView =[[UIView alloc]initWithFrame:CGRectMake(0 + width * j,CGRectGetMaxY(orderView.frame) , width, 90)];
            twoView.backgroundColor =[UIColor whiteColor];
            [twoView tapAction:^{
                
                if (verifTokenAndEnter) {
    
                if (j==0) {
                    
                    MyOrderViewController * myOrder =[[MyOrderViewController alloc]init];
                    myOrder.hidesBottomBarWhenPushed = YES;
                    myOrder.getGoods = @"getGoods";
                    [self.navigationController pushViewController:myOrder animated:YES];
                }
                
                if (j==1) {
                    SeeRefundingViewController * see =[[SeeRefundingViewController alloc]init];
                    see.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:see animated:YES];
                }

                
                if (j==2) {
                    SeeServiceViewController * see =[[SeeServiceViewController alloc]init];
                    see.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:see animated:YES];
                }
                }else {
                
                    LogingViewController * login =[[LogingViewController alloc]init];
                    login.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:login animated:YES];
                
                }
                
            }];
            
            UIImageView * imageView=[[UIImageView alloc]initWithFrame:CGRectMake((width - 40)/2, 10, 40, 40)];
            imageView.image = ImageName(twoArray[j]);

            [twoView addSubview:imageView];
            
            UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+5, width, 20)];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = RGB(0x666666);
            label.text = twoTitleArray[j];
            [twoView addSubview:label];
            
            [heardView addSubview:twoView];
            
        }
        
        UIView * line_twoView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(twoView.frame), WIDTH, 10)];
        line_twoView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [heardView addSubview:line_twoView];
        
        
        UIView * messageView = [self creatTitleViewFrame:CGRectMake(0, CGRectGetMaxY(line_twoView.frame), WIDTH, 50) andBageColor:[UIColor whiteColor] ImageName:@"icon_user_information" andTitle:@"我的信息" andSel:@selector(messageBtn) andMoreImageHidden:YES onView:heardView];
        
        NSArray * threeArray = @[@"icon_user_cart",@"icon_user_award_record",@"icon_user_shopping_mall"];
        NSArray * threeTitleArray = @[@"购物车",@"获奖记录",@"金币商城"];
        
        
        for (int j = 0; j<threeArray.count; j++) {
            
            UIView * mesage =[[UIView alloc]initWithFrame:CGRectMake(0 + width * j,CGRectGetMaxY(messageView.frame) , width, 90)];
            mesage.backgroundColor =[UIColor whiteColor];
            
            [mesage tapAction:^{
                
                if (verifTokenAndEnter) {
               
                if (j==0) {
                    CartViewController * car =[[CartViewController alloc]init];
                    car.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:car animated:YES];
                }else {
                    AddressListViewController * address =[[AddressListViewController alloc]init];
                    address.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:address animated:YES];
                }
                
            }else {
                
                LogingViewController * login =[[LogingViewController alloc]init];
                login.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:login animated:YES];
                
            }

             
            }];
            
            UIImageView * imageView=[[UIImageView alloc]initWithFrame:CGRectMake((width - 40)/2, 10, 40, 40)];
            imageView.image = ImageName(threeArray[j]);
            
            [mesage addSubview:imageView];
            
            UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+5, width, 20)];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = RGB(0x666666);
            label.text = threeTitleArray[j];
            [mesage addSubview:label];
            
            [heardView addSubview:mesage];
            
        }
        
        UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(line_twoView.frame)+130, WIDTH, 50)];
        bgView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [heardView addSubview:bgView];
        
        UIImageView * shopImage =[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/2-80, 17, 160, 16)];
        shopImage.image = ImageName(@"icon_user_title");
        [bgView addSubview:shopImage];
        
        return collectView;
    }else {
        
        return nil;
    }
}


-(void)iconBtnClick{

    if (verifTokenAndEnter) {
            ChangeMessageVC * change =[[ChangeMessageVC alloc]init];
            change.hidesBottomBarWhenPushed = YES;
            change.userDic = userDic;
            [self.navigationController pushViewController:change animated:YES];
    }else {
          LogingViewController * login =[[LogingViewController alloc]init];
          login.hidesBottomBarWhenPushed = YES;
          [self.navigationController pushViewController:login animated:YES];
    }

}

-(void)goldViewBtn:(UIButton *)btn{

    NSLog(@"金币");
}

-(void)pointViewBtn:(UIButton *)btn {
 
    if(verifTokenAndEnter){
        MyPointViewController * point =[[MyPointViewController alloc]init];
        point.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:point animated:YES];
    }else {
    
    LogingViewController * login =[[LogingViewController alloc]init];
    login.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:login animated:YES];
    
    }

}

-(void)orderBtn:(UIButton *)btn {

    if(verifTokenAndEnter){
       MyOrderViewController * myOrder =[[MyOrderViewController alloc]init];
       myOrder.hidesBottomBarWhenPushed = YES;
       myOrder.getGoods = @"all";
       [self.navigationController pushViewController:myOrder animated:YES];
    
    }else {
        
        LogingViewController * login =[[LogingViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }
}

-(void)messageBtn{

    NSLog(@"nothing...");
}

-(UIView *)creatTitleViewFrame:(CGRect)viewRec andBageColor:(UIColor *)col ImageName:(NSString *)imageName andTitle:(NSString *)title andSel:(SEL)sel andMoreImageHidden:(BOOL)bol onView:(UIView *)bgView{
    
    UIView * view =[[UIView alloc]initWithFrame:viewRec];
    view.backgroundColor = [UIColor whiteColor];
    
    UIView * labelView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    labelView.backgroundColor =col;
    
    [view addSubview:labelView];
    
    UIImageView * image =[[UIImageView alloc]initWithFrame:CGRectMake(10, 15, 20, 20)];
    image.image =[UIImage imageNamed:imageName];
    [labelView addSubview:image];
    
    UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(40, 15, 100, 20)];
    label.text = title;
    label.textColor =[UIColor blackColor];
    label.font =[UIFont systemFontOfSize:15];
    [labelView addSubview:label];
    
    
    UIImageView * moreImage =[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH -30, 25/2, 25, 25)];
    moreImage.image = ImageName(@"icon_user_more");
    moreImage.hidden = bol;
    [labelView addSubview:moreImage];
    
    UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, WIDTH, 50);
    button.backgroundColor =[UIColor clearColor];
    [button addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    
    [labelView addSubview:button];
    
    
    UIView * lineView =[[UIView alloc]initWithFrame:CGRectMake(0, 49.5, WIDTH, 0.5)];
    lineView.backgroundColor = RGB(0xe5e5e5);
    [labelView addSubview:lineView];
    
    [bgView addSubview:view];
    
    return view;
}


-(void)getUserMessageRequest{
    
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token")};
    
    [PostNetWorking postNetWorkingStr:RequestUrlStr(get_userMessage_api) andparameters:dic Success:^(id responseObject) {
        
        if (codeSucess) {
            
            userDic = responseObject[@"datas"];
  
        }else {
            
            if ([responseObject[@"code"] intValue]==220) {
                
                USER_DEFAULTSet(@"", @"token");
                USER_DEFAULTSet(@"", @"enter");
                USER_DEFAULTSet(@"", @"tokenVerify");
                USER_DEFAULTSet(@"", @"user_id");
                USER_DEFAULTSet(@"", @"phone");
                userDic = @{};
            }
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
         [_collectionView reloadData];
        
    } failed:^(NSError *error) {
        
        SHuiMBhudTextTimeStr(@"网络错误，请稍后再试");
    }];
    
}

-(void)getScoreGoodsListData{
    
    
    if (_totailPage != 0) {
        if(_page == _totailPage + 1){
            [_collectionView.mj_footer setState: MJRefreshStateNoMoreData];
            
            return ;
        }
    }
    NSDictionary * dic = @{
                           @"page":[NSString stringWithFormat:@"%d",_page],
                           @"page_num":@"10",
                           @"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token")
                           };
    
    //    SHuiMBhubNoTimeStr(@"正在加载...");
    [PostNetWorking postNetWorkingStr:RequestUrlStr(score_getGoodsList_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            _totailPage = [SHJudgeTools totailpageNumberForTotailNumber:responseObject[@"datas"][@"total_count"]];
            if (_page==1) {
                
                if (_dataArray) {
                    
                    [_dataArray removeAllObjects];
                }
                if ([responseObject[@"datas"][@"list"]  isKindOfClass:[NSArray class]]) {
                    
                    for (NSDictionary * dic in responseObject[@"datas"][@"list"]) {
                        
                        [_dataArray addObject:dic];
                    }
                }
            }else {
                
                if ([responseObject[@"datas"][@"list"]  isKindOfClass:[NSArray class]]) {
                    
                    for (NSDictionary * dic in responseObject[@"datas"][@"list"]) {
                        
                        [_dataArray addObject:dic];
                    }
                }
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                
                
                if (_dataArray.count>0) {
                       if (_dataArray.count<10) {
                        
                        _collectionView.mj_footer.hidden = YES;
                    }
                }else {
                    _collectionView.mj_footer.hidden = YES;
                   
                }
                [_collectionView.mj_header endRefreshing];
                [_collectionView.mj_footer endRefreshing];
                [_collectionView reloadData];
                
            });
            
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        [_collectionView.mj_header endRefreshing];
        [_collectionView.mj_footer endRefreshing];

        SHuiMBHidleYes;
        SHuiMBhudTextTimeStr(@"网络错误请重试！");
    }];
    
    
}




@end
